class Users::SessionsController < Devise::SessionsController
  layout 'users'
  # before_filter :configure_sign_in_params, only: [:create]

  # GET /resource/sign_in
  def new
    config = Config.where(name: 'login_ad').take
    @ad_image = config.file.url if config.file
    super
  end

  # POST /resource/sign_in
  # def create
  #   super
  # end

  # DELETE /resource/sign_out
  # def destroy
  #   super
  # end

  # protected

  # If you have extra params to permit, append them to the sanitizer.
  # def configure_sign_in_params
  #   devise_parameter_sanitizer.for(:sign_in) << :attribute
  # end

  # POST /resource/sign_in
  def create
    sign_out current_user if current_user
    self.resource = warden.authenticate!(auth_options)
    set_flash_message(:notice, :signed_in) if is_flashing_format?
    sign_in(resource_name, resource)

    if request.format == 'application/json'
      respond_to do |format|
        format.json  { render json: current_user.to_json(methods: [:credit_records_size]), status: :created }
      end
    else
      #yield resource if block_given
      respond_with resource, location: after_sign_in_path_for(resource)
    end
  end
  
  # DELETE /resource/sign_out
  def destroy
    signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
    set_flash_message :notice, :signed_out if signed_out && is_flashing_format?
    yield if block_given?
    respond_to_on_destroy
  end
end
